﻿using System.Web.Mvc;
using System.Linq;
using System.Collections.Generic;

namespace ASPItalia.ModelVirtualCasting.Web.Utils
{
    public class ConfigurableActionInvoker : ControllerActionInvoker
    {
        protected override FilterInfo GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
        {
            FilterInfo filter = base.GetFilters(controllerContext, actionDescriptor);

            if (filter.ExceptionFilters.Where(i => i is SendErrorMail).FirstOrDefault() == null)
                filter.ExceptionFilters.Add(new SendErrorMail());
            if (filter.ExceptionFilters.Where(i => i is HandleErrorAttribute).FirstOrDefault() == null)
                filter.ExceptionFilters.Add(new HandleErrorAttribute());

            return filter;
        }
    }
}